package br.com.salao.session;

import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;

import br.com.salao.ejb.dao.PaisDao;
import br.com.salao.ejb.dao.impl.PaisDaoImpl;
import br.com.salao.entity.Pais;

@Stateless
@Remote(PaisBase.class)
public class PaisBean implements PaisBase{
	
	/**
	 * @author Dri
	 */
	private static final long serialVersionUID = 1L;
	
	@PersistenceContext(unitName = "SalaoBeleza")
	private EntityManager em;
	
	private Logger logger = Logger.getLogger(PaisBean.class.getName());
	
	public PaisBean(){	
		//em =  JpaUtil.getEntityManager();		
	}
	
	@TransactionAttribute
	public boolean inserir(Pais pais){
		PaisDao dao = new PaisDaoImpl(em);
		try{
			System.out.println(pais.getNome());
			dao.inserir(pais);			
			return true;
		}catch (Exception e) {
			logger.error(e.getStackTrace() + e.getMessage() + e.getCause());
			e.printStackTrace();
			return false;
		}
	}
	
	 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
	public List<Pais> listarPaises(){		
		PaisDao dao = new PaisDaoImpl(em);		
		return dao.listar();
		
	}
	 
	 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
	public Pais localizarPaisPorId(int idpais){
		PaisDao dao = new PaisDaoImpl(em);	
		return dao.localizarPaisPorId(idpais);
	}

}
